package cn.shit;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class TestStream {
    public static void main(String[] args) {
        try {
            String txt = new String(Files.readAllBytes(Paths.get("D:\\PythonCode\\fuck\\ok.txt")));
            List<String> wordsList = Arrays.asList(txt.split("\\PL+"));
            // before
            long count = 0;
            for (String w : wordsList) {
                if (w.length() > 12) {
                    count++;
                }
            }
            System.out.println(count);
            /*
            1. 创建流
            2. 中间操作
            3. 最终操作产生结果
             */
            // SE 8
            long c = wordsList.stream().filter(w -> w.length() > 12).count();
            System.out.println(c);

            // 并行
            long d = wordsList.parallelStream().filter(w -> w.length() > 12).count();
            System.out.println(d);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
